package com.spider.controller;

import com.common.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * Decription
 * Created by ucmed on 2017/12/19.
 */
@RestController
@RequestMapping(value = "/spiderForSinglePage")
@Api(value = "爬取单个页面的数据")
public class HttpSpiderForSinglePage extends BaseController{

    @RequestMapping(value = "/dataMessage", method = RequestMethod.GET)
    @ApiOperation(value = "获取单个网页数据是否成功，true表示成功，false表示失败")
    @ApiImplicitParam(name = "path", value = "网页路径", dataType = "String", required = true, paramType = "query")
    public boolean getDataForSinglePage(String path) {
        if (path == null || "".equals(path)) {
            return false;
        }
        try {
            return downloadPageByPost(path);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
}
